package com.gxa.controller;

import com.gxa.pojo.CarBill;
import com.gxa.service.CarBillService;
import com.gxa.service.impl.CarBillServiceImpl;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "车辆账单管理控制器")
@RequestMapping("/carBill")
public class CarBillController {

    @Autowired
    private CarBillServiceImpl carBillService;

    @PostMapping("addBill")
    @ApiOperation("添加车辆账单")
    @ResponseBody
    public ResponseData addCarBill(@ApiParam(value = "车辆账单实体类信息",required = true) @RequestBody CarBill carBill){

        if(carBillService.addCarBill(carBill)){
            return new ResponseData(1,"添加成功");
        }else {
            return new ResponseData(0,"添加失败");
        }
    }

    @ApiOperation("查询所有车辆账单信息")
    @GetMapping("/showAllBillsByPage")
    @ResponseBody
    public ResponseData selectAllCarBillByPage(@ApiParam(value = "显示第几页",required = true) int pageNum,@ApiParam(value = "一页显示几组数据",required = true) int pageSize){

        return new ResponseData(11,"查询成功",carBillService.selectAllCarBillByPage(pageNum, pageSize));
    }

    @ApiOperation("根据车主姓名删除车辆账单")
    @DeleteMapping("/deleteCarBill")
    @ResponseBody
    public ResponseData deleteCarBillByCarOwner(@ApiParam(value = "要删除的车辆账单信息的车主姓名",required = true) String carOwner){

        if(carBillService.deleteCarBillByCarOwner(carOwner)){
            return new ResponseData(1,"删除成功");
        }else {
            return new ResponseData(0,"删除失败");
        }
    }


    @ApiOperation("根据车主姓名批量删除车辆账单")
    @DeleteMapping("/batchDelete")
    @ResponseBody
    public ResponseData batchDelete(@ApiParam(value = "要删除的车辆账单信息的车主姓名，多个姓名用‘，’隔开") String carOwners){

        String[] strings=carOwners.split(",");

//        for (String string : strings) {
//            System.out.println(string);
//        }

        if(carBillService.batchDeleteCarBill(strings)){
            return new ResponseData(1,"批量删除成功");
        }else {
            return new ResponseData(0,"批量删除失败");
        }
    }
}
